Skip to content

Set include_bias correctly in docs#1013

Merged
kbattocchi merged 2 commits intomainfrom
kebatt/correctDocs
Dec 2, 2025
Merged

Set include_bias correctly in docs#1013
kbattocchi merged 2 commits intomainfrom
kebatt/correctDocs

Conversation

@kbattocchi
Copy link
Collaborator

@kbattocchi kbattocchi commented Nov 17, 2025

This makes two changes:

  • Changes examples in our documentation that were using a featurizer that includes a bias term while also fitting an intercept; with an OLS final model inference is invalid because they are linearly dependent. This correctly generates warnings if you run the code, but it doesn't cause errors so we never noticed, I've updated the DML docs so that the only remaining warnings are due to convergence issues, not usage related.
  • Fixes a small issue with taking the Jacobian of a PolynomialFeatures object, which would incorrectly return nans instead of 0 when called with an argument of 0 (because we were effectively treating a term like y as x^0 y^1, and generating a derivative with respect to x of 0 x^(-1) y^1, which resulted in nan when evaluated at x=0 but 0 as expected when evaluated at any other value of x)

Signed-off-by: Keith Battocchi <kebatt@microsoft.com>
Signed-off-by: Keith Battocchi <kebatt@microsoft.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses two important issues: correcting documentation examples to avoid linear dependence between bias terms and intercepts in OLS models, and fixing a bug in Jacobian calculation for PolynomialFeatures that produced NaN values when evaluated at zero.

  • Fixed Jacobian calculation to avoid NaN when X contains zeros by only decrementing positive powers
  • Updated documentation examples to set include_bias=False for featurizers when fitting models with intercepts
  • Added test coverage for the zero-value case in Jacobian calculation

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
econml/utilities.py Fixed Jacobian calculation in _TransformerWrapper.jac() to avoid NaN by only decrementing positive polynomial powers
econml/iv/sieve/_tsls.py Applied same Jacobian fix in DPolynomialFeatures.transform() for consistency
econml/tests/test_treatment_featurization.py Updated test to use include_bias=True and added zero-value test case for NaN fix verification
doc/spec/estimation/dml.rst Corrected include_bias parameter in examples and updated test setup, but introduced generator expression bugs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link
Collaborator

@fverac fverac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@kbattocchi kbattocchi merged commit 55ea698 into main Dec 2, 2025
104 checks passed
@kbattocchi kbattocchi deleted the kebatt/correctDocs branch December 2, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants